//
//  NDCalculatorButton.swift
//  NyamanDana
//
//  Created by 李永彬 on 2025/10/25.
//

import SwiftUI

struct NDCalculatorButton: View {
    @Binding var isSelected: Bool
    let rateType: NDCalculatorRateType
    
    var body: some View {
        rateSection
    }
    
    var rateSection: some View {
        HStack(spacing: 5) {
            rateCheckbox
            rateText
        }
    }
    
    var rateCheckbox: some View {
        Button(action: toggleCalculatorAction) {
            ZStack {
                Circle()
                    .stroke(
                        isSelected ? Color.primaryOrange : Color.grayMedium,
                        lineWidth: isSelected ? 4 : 2
                    )
                    .frame(width: 12, height: 12)
                
                if isSelected {
                    Circle()
                        .fill(Color.primaryOrange)
                        .frame(width: 6, height: 6)
                }
            }
            .frame(width: 20, height: 20, alignment: .center)
            .contentShape(Rectangle())
        }
        .buttonStyle(PlainButtonStyle())
    }
    
    var rateText: some View {
        Text(rateType.title)
            .foregroundColor(Color(hex: "#000000"))
            .font(.montserratMedium(12))
    }
    
    func toggleCalculatorAction() {
        withAnimation(.easeInOut(duration: 0.2)) {
            isSelected = true
        }
    }
}

enum NDCalculatorRateType {
    case low
    case middle
    case high
    
    var title: String {
        switch self {
        case .low:
            return "0.02% /day"
        case .middle:
            return "0.03% /day"
        case .high:
            return "0.04% /day"
        }
    }
}
